package com.dxy.authresource.core;

import com.dxy.authresource.annotation.AuthResource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by cxf_dxy on 2018/10/26.
 */

@Component
@ConditionalOnClass(SpringApplicationContext.class)
public class LoadResource {

    public Map<String, Object> extractMethodMappings() {
        Map<String, Object> result = new HashMap<>();
        for (Map.Entry<String, AbstractHandlerMethodMapping> bean : SpringApplicationContext.getApplicationContext()
                .getBeansOfType(AbstractHandlerMethodMapping.class).entrySet()) {
            @SuppressWarnings("unchecked")
            Map<?, HandlerMethod> methods = bean.getValue().getHandlerMethods();
            for (Map.Entry<?, HandlerMethod> method : methods.entrySet()) {
                result.put(method.getKey().toString(), DataBuilder.build(method,bean));
            }
        }
        return result;
    }

}
